package com.prs.crm.action.oa;

import java.io.File;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Comment;
import com.prs.crm.domain.oa.CommentChild;
import com.prs.crm.domain.oa.NewsReceive;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.domain.oa.PictureNews;
import com.prs.crm.domain.oa.PictureNewsCollect;
import com.prs.crm.domain.oa.PictureNewsCollectType;
import com.prs.crm.domain.oa.PictureNewsReceive;
import com.prs.crm.service.AttachmentService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.oa.CommentChildService;
import com.prs.crm.service.oa.CommentService;
import com.prs.crm.service.oa.PictureNewsCollectService;
import com.prs.crm.service.oa.PictureNewsCollectTypeService;
import com.prs.crm.service.oa.PictureNewsReceiveService;
import com.prs.crm.service.oa.PictureNewsService;

public class PictureNewsAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private PictureNews pictureNews;
	private PictureNewsService pictureNewsService;
	private PersonService personService;
	private String accepts;
	private PictureNewsReceive pictureNewsReceive;
	private PictureNewsReceiveService pictureNewsReceiveService;
	private File upload;
	private String uploadFileName;
	private File upload2;
	private String upload2FileName;
	private AttachmentService attachmentService;
	private Integer[] pictureIds;
	private Integer[] receiveIds;
	private String type;
	private CommentService commentService;
	private CommentChildService commentChildService;
	private List<PictureNewsCollectType> pictureNewsCollectTypes;
	private PictureNewsCollectTypeService pictureNewsCollectTypeService;
	private PictureNewsCollect pictureNewsCollect;
	private PictureNewsCollectService pictureNewsCollectService;
	private Integer[] collectIds;
 	public Integer[] getCollectIds() {
		return collectIds;
	}
	public void setCollectIds(Integer[] collectIds) {
		this.collectIds = collectIds;
	}
	public PictureNewsCollect getPictureNewsCollect() {
		return pictureNewsCollect;
	}
	public void setPictureNewsCollect(PictureNewsCollect pictureNewsCollect) {
		this.pictureNewsCollect = pictureNewsCollect;
	}
	public PictureNewsCollectService getPictureNewsCollectService() {
		return pictureNewsCollectService;
	}
	public void setPictureNewsCollectService(
			PictureNewsCollectService pictureNewsCollectService) {
		this.pictureNewsCollectService = pictureNewsCollectService;
	}
	public PictureNewsCollectTypeService getPictureNewsCollectTypeService() {
		return pictureNewsCollectTypeService;
	}
	public void setPictureNewsCollectTypeService(
			PictureNewsCollectTypeService pictureNewsCollectTypeService) {
		this.pictureNewsCollectTypeService = pictureNewsCollectTypeService;
	}
	public List<PictureNewsCollectType> getPictureNewsCollectTypes() {
		return pictureNewsCollectTypes;
	}
	public void setPictureNewsCollectTypes(
			List<PictureNewsCollectType> pictureNewsCollectTypes) {
		this.pictureNewsCollectTypes = pictureNewsCollectTypes;
	}
	@Action("editPictureNews")
	public String editPictureNews() {
		if(this.pictureIds!=null){
			this.pictureNews=this.pictureNewsService.get(pictureIds[0]);
		}
		return SUCCESS;
	}
	@Action("listPictureNews")
	public String listPictureNews() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PictureNews.class);
		criteria.add(Restrictions.eq("oabox", 1));
		criteria.add(Restrictions.eq("recorder.id", AppContext.getAccountContext().currentUser().getId()));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.pictureNewsService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("listPictureNewsDraft")
	public String listPictureNewsDraft() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PictureNews.class);
		criteria.add(Restrictions.eq("oabox", 0));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.pictureNewsService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("listPictureNewsReceive")
	public String listPictureNewsReceive() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PictureNewsReceive.class);
		criteria.add(Restrictions.eq("receivePerson.id", AppContext.getAccountContext().currentUser().getId()));
		criteria.add(Restrictions.eq("oabox", 1));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.pictureNewsReceiveService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("viewPictureNews")
	public String viewPictureNews() {
		return SUCCESS;
	}
	@Action("viewPictureNewsReceive")
	public String viewPictureNewsReceive() {
		if(this.receiveIds!=null){
			this.pictureNewsReceive=this.pictureNewsReceiveService.get(receiveIds[0]);
		}
		
		if(pictureNewsReceive.getState().equals("未读")){
			pictureNewsReceive.setState("已读");
			this.pictureNewsReceiveService.submit(pictureNewsReceive);
		}
//		this.pictureNews=this.pictureNewsReceive.getPictureNews();
		return SUCCESS;
	}
	@Action("forWardPictureNews")
	public String forWardPictureNews() {
		if (pictureNews!=null) {
			pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
					"From: "+pictureNews.getRecorder().getResume().getName()+"<BR>" +
					"To："+pictureNews.getReceive()+"<BR>" +
					"Title："+pictureNews.getTitle()+"<BR>" +
					"Content: <BR>"+pictureNews.getContent());
			pictureNews.setReceive("");
			pictureNews.setTitle("Fw: "+pictureNews.getTitle());
		}
		if (pictureNewsReceive!=null) {
//			PictureNews pn=this.getPictureNewsService().getPictureNewsId(pictureNewsReceive.getPictureNewsId());
//			if (pn!=null) {
				pictureNews=new PictureNews();
				pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
						"From: "+pictureNewsReceive.getRecorder().getResume().getName()+"<BR>" +
						"To："+pictureNewsReceive.getReceivePerson().getResume().getName()+"<BR>" +
						"Title："+pictureNewsReceive.getTitle()+"<BR>" +
						"Content: <BR>"+pictureNewsReceive.getContent());
				pictureNews.setPicture(pictureNewsReceive.getPicture());
				pictureNews.setReceive("");
				pictureNews.setTitle("Fw: "+pictureNewsReceive.getTitle());
				if (pictureNewsReceive.getAttach()!=null) {
					pictureNews.setAttach(pictureNewsReceive.getAttach());
				}
//			}
		}
		if(pictureIds!=null){
			this.pictureNews=this.pictureNewsService.get(pictureIds[0]);
			pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
							"From: "+pictureNews.getRecorder().getResume().getName()+"<BR>" +
							"To："+pictureNews.getReceive()+"<BR>" +
							"Title："+pictureNews.getTitle()+"<BR>" +
							"Content: <BR>"+pictureNews.getContent());
			pictureNews.setReceive("");
			pictureNews.setTitle("Fw: "+pictureNews.getTitle());
		}
		if (receiveIds!=null) {
			this.pictureNewsReceive=this.getPictureNewsReceiveService().get(receiveIds[0]);
//			PictureNews pn=this.getPictureNewsService().getPictureNewsId(pictureNewsReceive.getPictureNewsId());
//			if (pn!=null) {
				pictureNews=new PictureNews();
				pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
						"From: "+pictureNewsReceive.getRecorder().getResume().getName()+"<BR>" +
						"To："+pictureNewsReceive.getReceivePerson().getResume().getName()+"<BR>" +
						"Title："+pictureNewsReceive.getTitle()+"<BR>" +
						"Content: <BR>"+pictureNewsReceive.getContent());
				pictureNews.setPicture(pictureNewsReceive.getPicture());
				pictureNews.setReceive("");
				pictureNews.setTitle("Fw: "+pictureNewsReceive.getTitle());
				if (pictureNewsReceive.getAttach()!=null) {
					pictureNews.setAttach(pictureNewsReceive.getAttach());
//				}
			}
		}
		return SUCCESS;
	}
	@Action(value = "sendPictureNews", results = {
			@Result(name = "success", type = "redirect", location = "editPictureNews"),
			@Result(name = "error", type = "chain", location = "editPictureNews") })
	public String sendNews() {
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			if (attach.getContentType().equals("gif") || attach.getContentType().equals("jpg") || attach.getContentType().equals("bmp") || attach.getContentType().equals("png")) {
				this.getAttachmentService().save(attach);
				if(attach.getPath() != null) {
					pictureNews.setPicture(attach.getPath());
					pictureNews.setPictureName(attach.getName());
					long i=upload.length();
					long a=i/1024;
					int b=(new Long(a).intValue())+1;
					String c=Long.toString((long)b);
					pictureNews.setPictureSize(c+"KB");
				}
			}else{
				this.addActionError("上传图片格式不正确，请上传格式为jpg、gif、png、bmp的图片");
				return ERROR;
			}
		}
		if(upload2!=null){
			Attachment attach1=FileUtil.getInstance().createAttach(upload2, upload2FileName);
			this.getAttachmentService().save(attach1);
			pictureNews.setAttach(attach1);
		}
		//已发新闻设置
		System.out.println(pictureNews.getAccepts());
		if (pictureNews.getId()==null) {
			pictureNews.setAccepts(accepts);
		}
		pictureNews.setCreatTime(new Date());
		pictureNews.setOabox(1);
		pictureNews.setTop(0);
		this.pictureNewsService.save(pictureNews);
		//已收新闻设置
		Collection<Person> acceptPersons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(pictureNews.getAccepts().split(",")));
		Iterator<Person> iter = acceptPersons.iterator();
		while(iter.hasNext()) {
			Person person = iter.next();
			PictureNewsReceive re=new PictureNewsReceive();
			re.setPictureNewsId(pictureNews.getId());
			re.setTitle(pictureNews.getTitle());
			re.setContent(pictureNews.getContent());
			re.setDegree(pictureNews.getDegree());
			if (pictureNews.getAttach()!=null) {
				re.setAttach(pictureNews.getAttach());
			}
			re.setIsComment(pictureNews.getIsComment());
			re.setPicture(pictureNews.getPicture());
			re.setPictureName(pictureNews.getPictureName());
			re.setPictureSize(pictureNews.getPictureSize());
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser()); //发送人
			re.setReceivePerson(person);  //接收人
			re.setState("未读");
			this.pictureNewsReceiveService.save(re);
		}
		this.setPrompt("新闻发送成功");
		return SUCCESS;
	}
	@Action(value = "sendPicture", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNews"),
			@Result(name = "error", type = "chain", location = "listPictureNews") })
	public String sendPicture() {
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			if (attach.getContentType().equals("gif") || attach.getContentType().equals("jpg") || attach.getContentType().equals("bmp") || attach.getContentType().equals("png")) {
				this.getAttachmentService().save(attach);
				if(attach.getPath() != null) {
					pictureNews.setPicture(attach.getPath());
					pictureNews.setPictureName(attach.getName());
					long i=upload.length();
					long a=i/1024;
					int b=(new Long(a).intValue())+1;
					String c=Long.toString((long)b);
					pictureNews.setPictureSize(c+"KB");
				}
			}else{
				this.addActionError("上传图片格式不正确，请上传格式为jpg、gif、png、bmp的图片");
				return ERROR;
			}
		}
		if(upload2!=null){
			Attachment attach1=FileUtil.getInstance().createAttach(upload2, upload2FileName);
			this.getAttachmentService().save(attach1);
			pictureNews.setAttach(attach1);
		}
		//已发新闻设置
		pictureNews.setAccepts(accepts);
		pictureNews.setCreatTime(new Date());
		pictureNews.setOabox(1);
		this.pictureNewsService.save(pictureNews);
		//已收新闻设置
		Collection<Person> acceptPersons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(accepts.split(",")));
		Iterator<Person> iter = acceptPersons.iterator();
		while(iter.hasNext()) {
			Person person = iter.next();
			PictureNewsReceive re=new PictureNewsReceive();
			re.setPictureNewsId(pictureNews.getId());
			re.setTitle(pictureNews.getTitle());
			re.setContent(pictureNews.getContent());
			re.setDegree(pictureNews.getDegree());
			if (pictureNews.getAttach()!=null) {
				re.setAttach(pictureNews.getAttach());
			}
			re.setPicture(pictureNews.getPicture());
			re.setPictureName(pictureNews.getPictureName());
			re.setIsComment(pictureNews.getIsComment());
			re.setPicture(pictureNews.getPicture());
			re.setPictureName(pictureNews.getPictureName());
			re.setPictureSize(pictureNews.getPictureSize());
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser()); //发送人
			re.setReceivePerson(person);  //接收人
			re.setState("未读");
			this.pictureNewsReceiveService.save(re);
		}
		this.setPrompt("新闻发送成功");
		return SUCCESS;
	}
	@Action(value = "sendPictureNewsDraft", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsDraft"),
			@Result(name = "error", type = "chain", location = "listPictureNewsDraft") })
	public String sendPictureNewsDraft() {
		if(this.pictureIds!=null){
			this.pictureNews=this.pictureNewsService.get(pictureIds[0]);
		}
		if (upload==null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			if (attach.getContentType().equals("gif") || attach.getContentType().equals("jpg") || attach.getContentType().equals("bmp") || attach.getContentType().equals("png")) {
				this.getAttachmentService().save(attach);
				if(attach.getPath() != null) {
					pictureNews.setPicture(attach.getPath());
					pictureNews.setPictureName(attach.getName());
					long i=upload.length();
					long a=i/1024;
					int b=(new Long(a).intValue())+1;
					String c=Long.toString((long)b);
					pictureNews.setPictureSize(c+"KB");
				}
			}else{
				this.addActionError("上传图片格式不正确，请上传格式为jpg、gif、png、bmp的图片");
				return ERROR;
			}
		}
		if(upload2!=null){
			Attachment attach1=FileUtil.getInstance().createAttach(upload2, upload2FileName);
			this.getAttachmentService().save(attach1);
			pictureNews.setAttach(attach1);
		}
		//已发新闻设置
		pictureNews.setAccepts(accepts);
		pictureNews.setCreatTime(new Date());
		pictureNews.setOabox(1);
		this.pictureNewsService.save(pictureNews);
		//已收新闻设置
		Collection<Person> acceptPersons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(pictureNews.getAccepts().split(",")));
		Iterator<Person> iter = acceptPersons.iterator();
		while(iter.hasNext()) {
			Person person = iter.next();
			PictureNewsReceive re=new PictureNewsReceive();
			re.setPictureNewsId(pictureNews.getId());
			re.setTitle(pictureNews.getTitle());
			re.setContent(pictureNews.getContent());
			re.setDegree(pictureNews.getDegree());
			if (pictureNews.getAttach()!=null) {
				re.setAttach(pictureNews.getAttach());
			}
			re.setIsComment(pictureNews.getIsComment());
			re.setPicture(pictureNews.getPicture());
			re.setPictureName(pictureNews.getPictureName());
			re.setPictureSize(pictureNews.getPictureSize());
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser()); //发送人
			re.setReceivePerson(person);  //接收人
			re.setState("未读");
			this.pictureNewsReceiveService.save(re);
		}
		this.setPrompt("新闻发送成功");
		return SUCCESS;
	}
	@Action(value = "ReplyPic", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsReceive"),
			@Result(name = "error", type = "chain", location = "ReplyPictureNews?pictureNews=${pictureNews.getId()}") })
	public String ReplyPic() {
		pictureNews.setCreatTime(new Date());
		this.pictureNewsService.save(pictureNews);
		//已收新闻设置
		Collection<Person> acceptPersons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(accepts.split(",")));
		Iterator<Person> iter = acceptPersons.iterator();
		while(iter.hasNext()) {
			Person person = iter.next();
			PictureNewsReceive re=new PictureNewsReceive();
			re.setPictureNewsId(pictureNews.getId());
			re.setTitle(pictureNews.getTitle());
			re.setContent(pictureNews.getContent());
			re.setDegree(pictureNews.getDegree());
			if (pictureNews.getAttach()!=null) {
				re.setAttach(pictureNews.getAttach());
			}
			re.setIsComment(pictureNews.getIsComment());
			re.setPicture(pictureNews.getPicture());
			re.setPictureName(pictureNews.getPictureName());
			re.setPictureSize(pictureNews.getPictureSize());
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser()); //发送人
			re.setReceivePerson(person);  //接收人
			re.setState("未读");
			this.pictureNewsReceiveService.save(re);
		}
		this.setPrompt("新闻发送成功");
		return SUCCESS;
	}
	
	@Action(value = "saveDraftByPicture", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNews"),
			@Result(name = "error", type = "chain", location = "listPictureNews") })
	public String saveDraftByPicture() {
//		Attach attach = FileUtil.getInstance().saveFile(upload, uploadFileName, "", Constrains.UPLOAD_DIR_SCHEDULE);
//		if(attach.getSrc() != null) {
//			pictureNews.setPicture(attach.getSrc());
//			pictureNews.setPictureName(attach.getName());
//			long i=upload.length();
//			long a=i/1024;
//			int b=(new Long(a).intValue())+1;
//			String c=Long.toString((long)b);
//			pictureNews.setPictureSize(c+"KB");
//		}
//		if(upload2!=null){
//			pictureNews.setAttach(FileUtil.getInstance().createAttach(upload2, upload2FileName));
//		}
		if (upload==null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			if (attach.getContentType().equals("gif") || attach.getContentType().equals("jpg") || attach.getContentType().equals("bmp") || attach.getContentType().equals("png")) {
				this.getAttachmentService().save(attach);
				if(attach.getPath() != null) {
					pictureNews.setPicture(attach.getPath());
					pictureNews.setPictureName(attach.getName());
					long i=upload.length();
					long a=i/1024;
					int b=(new Long(a).intValue())+1;
					String c=Long.toString((long)b);
					pictureNews.setPictureSize(c+"KB");
				}
			}else{
				this.addActionError("上传图片格式不正确，请上传格式为jpg、gif、png、bmp的图片");
				return ERROR;
			}
		}
		if(upload2!=null){
			Attachment attach1=FileUtil.getInstance().createAttach(upload2, upload2FileName);
			this.getAttachmentService().save(attach1);
			pictureNews.setAttach(attach1);
		}
		this.pictureNews.setOabox(0);
		this.pictureNews.setAccepts(accepts);
		this.pictureNewsService.submit(pictureNews);
		return SUCCESS;
	}
	@Action(value = "saveDraftPicture", results = {
			@Result(name = "success", type = "redirect", location = "editPictureNews"),
			@Result(name = "error", type = "chain", location = "editPictureNews") })
	public String saveDraftPicture() {
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			if (attach.getContentType().equals("gif") || attach.getContentType().equals("jpg") || attach.getContentType().equals("bmp") || attach.getContentType().equals("png")) {
				this.getAttachmentService().save(attach);
				if(attach.getPath() != null) {
					pictureNews.setPicture(attach.getPath());
					pictureNews.setPictureName(attach.getName());
					long i=upload.length();
					long a=i/1024;
					int b=(new Long(a).intValue())+1;
					String c=Long.toString((long)b);
					pictureNews.setPictureSize(c+"KB");
				}
			}else{
				this.addActionError("上传图片格式不正确，请上传格式为jpg、gif、png、bmp的图片");
				return ERROR;
			}
			
		}
		if(upload2!=null){
			Attachment attach1=FileUtil.getInstance().createAttach(upload2, upload2FileName);
			this.getAttachmentService().save(attach1);
			pictureNews.setAttach(attach1);
		}
		pictureNews.setCreatTime(new Date());
		pictureNews.setOabox(0);
		pictureNews.setAccepts(accepts);
		this.pictureNewsService.save(pictureNews);
		return SUCCESS;
	}
	@Action(value = "removePictureNews", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNews"),
			@Result(name = "error", type = "chain", location = "listPictureNews") })
	public String removePictureNews() {
		for(Integer id:pictureIds){
			this.pictureNews=this.pictureNewsService.get(id);
			if(pictureNews.getCollects().size()!=0){
				this.addActionError("新闻已收藏,不能删除");
				return ERROR;
			}
			for (int a = 0; a < pictureNews.getComment().size(); a++) {
				Comment c=pictureNews.getComment().get(a);
					for (int j = 0; j < c.getChilds().size(); j++) {
					CommentChild cc=c.getChilds().get(j);
					this.getCommentChildService().remove(cc);
				    }
					this.getCommentService().remove(c);
			}
		}
		this.pictureNewsService.batchRemove(pictureIds);
		return SUCCESS;
	}
	@Action(value = "removePictureNewsDraft", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsDraft"),
			@Result(name = "error", type = "chain", location = "listPictureNewsDraft") })
	public String removePictureNewsDraft() {
		for(Integer id:pictureIds){
			this.pictureNews=this.pictureNewsService.get(id);
			if(pictureNews.getCollects().size()!=0){
				this.addActionError("新闻已收藏,不能删除");
				return ERROR;
			}
		}
		this.pictureNewsService.batchRemove(pictureIds);
		return SUCCESS;
	}
	@Action(value = "deletePictureNews", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNews"),
			@Result(name = "error", type = "chain", location = "viewPictureNews?pictureNews=${pictureNews.geId()}") })
	public String deletePictureNews() {
		if(pictureNews.getCollects().size()!=0){
				this.addActionError("新闻已收藏,不能删除");
				return ERROR;
			}
		for (int a = 0; a < pictureNews.getComment().size(); a++) {
			Comment c=pictureNews.getComment().get(a);
				for (int j = 0; j < c.getChilds().size(); j++) {
				CommentChild cc=c.getChilds().get(j);
				this.getCommentChildService().remove(cc);
			    }
				this.getCommentService().remove(c);
		}
		this.pictureNewsService.remove(this.pictureNews);
		return SUCCESS;
	}
	@Action(value = "removePictureNewsReceive", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsReceive"),
			@Result(name = "error", type = "chain", location = "listPictureNewsReceive") })
	public String removePictureNewsReceive() {
		for(Integer id:receiveIds){
			this.pictureNewsReceive=this.pictureNewsReceiveService.get(id);
			for (int a = 0; a < pictureNewsReceive.getComment().size(); a++) {
				Comment c=pictureNewsReceive.getComment().get(a);
					for (int j = 0; j < c.getChilds().size(); j++) {
					CommentChild cc=c.getChilds().get(j);
					this.getCommentChildService().remove(cc);
				    }
					this.getCommentService().remove(c);
			}
		}
		this.pictureNewsReceiveService.batchRemove(receiveIds);
		return SUCCESS;
	}
	@Action(value = "deletePictureNewsReceive", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsReceive"),
			@Result(name = "error", type = "chain", location = "listPictureNewsReceive") })
	public String deletePictureNewsReceive() {
		for (int a = 0; a < pictureNewsReceive.getComment().size(); a++) {
			Comment c=pictureNewsReceive.getComment().get(a);
				for (int j = 0; j < c.getChilds().size(); j++) {
				CommentChild cc=c.getChilds().get(j);
				this.getCommentChildService().remove(cc);
			    }
				this.getCommentService().remove(c);
		}
		this.pictureNewsReceiveService.remove(pictureNewsReceive);
		return SUCCESS;
	}
	@Action(value = "saveDraftPic", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNewsReceive"),
			@Result(name = "error", type = "chain", location = "listPictureNewsReceive") })
	public String saveDraftPic() {
		this.pictureNews.setOabox(0);
		this.pictureNewsService.submit(pictureNews);
		return SUCCESS;
	}
	@Action("ReplyPictureNews")
	public String ReplyPictureNews() {
		if(receiveIds!=null){
			this.pictureNewsReceive=this.pictureNewsReceiveService.get(receiveIds[0]);
//			this.pictureNews=this.pictureNewsReceive.getPictureNews();
		}
		PictureNews pn=this.getPictureNewsService().getPictureNewsId(pictureNewsReceive.getPictureNewsId());
		if(pn!=null){
			if(type.equals("1")){  //回复全部
				pictureNews=new PictureNews();
				pictureNews.setReceive(pn.getReceive());
				pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
								"From: "+pn.getRecorder().getResume().getName()+"<BR>" +
								"To："+pn.getReceive()+"<BR>" +
								"Title："+pn.getTitle()+"<BR>" +
								"Content: <BR>"+pn.getContent());
				this.accepts=pn.getAccepts();
				pictureNews.setTitle("Re: "+pn.getTitle());
				pictureNews.setPicture(pn.getPicture());
			}else{
				pictureNews=new PictureNews();
				pictureNews.setReceive(pn.getReceive());
				String[] receive=pn.getReceive().split(",");
				String[] acc=pn.getAccepts().split(",");
				pictureNews.setContent("<BR><BR>----- Original Message ----- <BR>" +
						"From: "+pn.getRecorder().getResume().getName()+"<BR>" +
						"To："+receive[0]+"<BR>" +
						"Title："+pn.getTitle()+"<BR>" +
						"Content: <BR>"+pn.getContent());
				this.accepts=acc[0];
				pictureNews.setTitle("Re: "+pn.getTitle());
				pictureNews.setPicture(pn.getPicture());
			}
		}
		return SUCCESS;
	}
	@Action("listPictureViewNews")
	public String listPictureViewNews() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PictureNews.class);
		criteria.add(Restrictions.eq("oabox", 1));
		criteria.addOrder(Order.desc("top"));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.pictureNewsService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action(value = "savePictureNewsTop", results = {
			@Result(name = "success", type = "redirect", location = "listPictureViewNews"),
			@Result(name = "error", type = "chain", location = "listPictureViewNews") })
	public String savePictureNewsTop(){
		if(pictureIds!=null){
			this.pictureNews=this.getPictureNewsService().get(pictureIds[0]);
		}
		pictureNews.setTop(1);
		this.getPictureNewsService().save(pictureNews);
		return SUCCESS;
	}
	@Action(value = "saveNotPictureTop", results = {
			@Result(name = "success", type = "redirect", location = "listPictureViewNews"),
			@Result(name = "error", type = "chain", location = "listPictureViewNews") })
	public String saveNotPictureTop(){
		if(pictureIds!=null){
			this.pictureNews=this.getPictureNewsService().get(pictureIds[0]);
		}
		pictureNews.setTop(0);
		this.getPictureNewsService().save(pictureNews);
		return SUCCESS;
	}
	
	@Action(value = "removePictureNew", results = {
			@Result(name = "success", type = "redirect", location = "listPictureNews"),
			@Result(name = "error", type = "chain", location = "listPictureNews") })
	public String removePictureNew() {
		for(Integer id:pictureIds){
			this.pictureNews=this.pictureNewsService.get(id);
			if(pictureNews.getCollects().size()!=0){
				this.addActionError("新闻已收藏,不能删除");
				return ERROR;
			}
			for (int a = 0; a < pictureNews.getComment().size(); a++) {
				Comment c=pictureNews.getComment().get(a);
					for (int j = 0; j < c.getChilds().size(); j++) {
					CommentChild cc=c.getChilds().get(j);
					this.getCommentChildService().remove(cc);
				    }
					this.getCommentService().remove(c);
			}
			
		}
		this.pictureNewsService.batchRemove(pictureIds);
		return SUCCESS;
	}
	@Action("viewPictureNew")
	public String viewPictureNew() {
		return SUCCESS;
	}
	
	@Action(value = "editPictureNewsMove", results = {
			@Result(name = "error", type = "chain", location = "listPictureNewsCollect") })
		public String editPictureNewsMove(){
			if (collectIds!=null) {
				this.pictureNewsCollect=this.getPictureNewsCollectService().get(collectIds[0]);
			}else{
				this.addActionError("请选择一行进行操作！");
				return ERROR;
			}
			pictureNewsCollectTypes=this.getPictureNewsCollectTypeService().getAll();
			return SUCCESS;
		}
		@Action(value = "savePictureNewsMove", results = {
				@Result(name = "success", type = "redirect", location = "listPictureNewsCollect"),
				@Result(name = "error", type = "chain", location = "editPictureNewsMove") })
		public String savePictureNewsMove(){
			if (pictureNewsCollect==null) {
				this.addActionError("请选择一项进行移动！");
				return ERROR;
			}
			this.getPictureNewsCollectService().submit(pictureNewsCollect);
			return SUCCESS;
		}
	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PictureNews getPictureNews() {
		return pictureNews;
	}

	public void setPictureNews(PictureNews pictureNews) {
		this.pictureNews = pictureNews;
	}

	public PictureNewsService getPictureNewsService() {
		return pictureNewsService;
	}

	public void setPictureNewsService(PictureNewsService pictureNewsService) {
		this.pictureNewsService = pictureNewsService;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public String getAccepts() {
		return accepts;
	}
	public void setAccepts(String accepts) {
		this.accepts = accepts;
	}
	public PictureNewsReceive getPictureNewsReceive() {
		return pictureNewsReceive;
	}
	public void setPictureNewsReceive(PictureNewsReceive pictureNewsReceive) {
		this.pictureNewsReceive = pictureNewsReceive;
	}
	public PictureNewsReceiveService getPictureNewsReceiveService() {
		return pictureNewsReceiveService;
	}
	public void setPictureNewsReceiveService(
			PictureNewsReceiveService pictureNewsReceiveService) {
		this.pictureNewsReceiveService = pictureNewsReceiveService;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public AttachmentService getAttachmentService() {
		return attachmentService;
	}
	public void setAttachmentService(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}
	public File getUpload2() {
		return upload2;
	}
	public void setUpload2(File upload2) {
		this.upload2 = upload2;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public String getUpload2FileName() {
		return upload2FileName;
	}
	public void setUpload2FileName(String upload2FileName) {
		this.upload2FileName = upload2FileName;
	}
	public Integer[] getPictureIds() {
		return pictureIds;
	}
	public void setPictureIds(Integer[] pictureIds) {
		this.pictureIds = pictureIds;
	}
	public Integer[] getReceiveIds() {
		return receiveIds;
	}
	public void setReceiveIds(Integer[] receiveIds) {
		this.receiveIds = receiveIds;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public CommentService getCommentService() {
		return commentService;
	}
	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}
	public CommentChildService getCommentChildService() {
		return commentChildService;
	}
	public void setCommentChildService(CommentChildService commentChildService) {
		this.commentChildService = commentChildService;
	}
	
}
